package com.chen.hotel.Service.impl;

import com.chen.hotel.Service.TypeService;
import com.chen.hotel.dao.TypeDao;
import com.chen.hotel.domain.Type;
import com.chen.hotel.utils.CopyNotNullUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;



@Service
public class TypeServiceImpl implements TypeService {
    @Autowired
    private TypeDao dao;

    @Override
    public Type create(Type type) {
        return this.dao.save(type);
    }

    @Override
    public Type findById(Integer id) {
        return this.dao.findById(id).get();
    }

    @Override
    public void delete(Integer id) {
        this.dao.deleteById(id);
    }

    @Override
    public Type update(Type type) {
        Type t = this.findById(type.getId());
        t = CopyNotNullUtil.copyNoNullProperties(type, t);
        return this.dao.save(t);
    }

    @Override
    public Page<Type> findAll(Pageable pageable) {
        return this.dao.findAll(pageable);
    }
}
